package im.yisme.model.game;

public class AccuracyAssessingSystem {

	private static final float ACTIVE_TIME_BEFORE=1000;
	private static final float ACTIVE_TIME_AFTER=500;
	private static final float TOLERABLE_ERROR_TIME_BEFORE=200;
	private static final float TOLERABLE_ERROR_TIME_AFTER=100;
	
	/**
	 * 
	 * @param hitTime
	 * @param bestTime
	 * @return -1：音符处于未激活状态
	 */
	public float getAccuracy(int hitTime,int bestTime){
		
		if(hitTime<bestTime-ACTIVE_TIME_BEFORE || hitTime>bestTime+ACTIVE_TIME_AFTER) return -1;
		
		long distance=bestTime-hitTime;
		
		if(distance >= 0){
			
			if(distance<=TOLERABLE_ERROR_TIME_BEFORE) return 1.0f;
			else{
				return (ACTIVE_TIME_BEFORE-distance)/ACTIVE_TIME_BEFORE;
			}
			
		}
		else{
			distance=-distance;
			
			if(distance<=TOLERABLE_ERROR_TIME_AFTER) return 1.0f;
			else{
				return (ACTIVE_TIME_AFTER-distance)/ACTIVE_TIME_AFTER;
			}
		}
	}

	public static float getActiveTimeAfter() {
		return ACTIVE_TIME_AFTER;
	}
}
